﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.TrayVMs
{
    public partial class TrayListVM : BasePagedListVM<Tray_View, TraySearcher>
    {
        
        protected override IEnumerable<IGridColumn<Tray_View>> InitGridHeader()
        {
            return new List<GridColumn<Tray_View>>{
                
                this.MakeGridHeader(x => x.Tray_TrayCode).SetTitle(@Localizer["Page.托盘编码"].Value),
                this.MakeGridHeader(x => x.Tray_TrayName).SetTitle(@Localizer["Page.托盘名称"].Value),
                this.MakeGridHeader(x => x.Tray_TrayDescription).SetTitle(@Localizer["Page.描述"].Value),
                this.MakeGridHeader(x => x.Tray_TrayStatus).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.Tray_Note).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.Tray_TrayLine).SetTitle(@Localizer["Page.当前产线"].Value),
                this.MakeGridHeader(x => x.Tray_TrayStation).SetTitle(@Localizer["Page.当前工位"].Value),
                this.MakeGridHeader(x => x.Tray_UsedTimes).SetTitle(@Localizer["Page.使用寿命"].Value),
                this.MakeGridHeader(x => x.Tray_PlannedTimes).SetTitle(@Localizer["Page.预计寿命"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Tray_View> GetSearchQuery()
        {
            var query = DC.Set<Tray>()
                
                .CheckContain(Searcher.TrayCode, x=>x.TrayCode)
                .CheckContain(Searcher.TrayName, x=>x.TrayName)
                .CheckContain(Searcher.TrayDescription, x=>x.TrayDescription)
                .CheckContain(Searcher.TrayStatus, x=>x.TrayStatus)
                .CheckContain(Searcher.Note, x=>x.Note)
                .CheckContain(Searcher.TrayLine, x=>x.TrayLine)
                .CheckContain(Searcher.TrayStation, x=>x.TrayStation)
                .CheckEqual(Searcher.UsedTimes, x=>x.UsedTimes)
                .CheckEqual(Searcher.PlannedTimes, x=>x.PlannedTimes)
                .Select(x => new Tray_View
                {
				    ID = x.ID,
                    
                    Tray_TrayCode = x.TrayCode,
                    Tray_TrayName = x.TrayName,
                    Tray_TrayDescription = x.TrayDescription,
                    Tray_TrayStatus = x.TrayStatus,
                    Tray_Note = x.Note,
                    Tray_TrayLine = x.TrayLine,
                    Tray_TrayStation = x.TrayStation,
                    Tray_UsedTimes = x.UsedTimes,
                    Tray_PlannedTimes = x.PlannedTimes,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Tray_View: Tray
    {
        
        public string Tray_TrayCode { get; set; }
        public string Tray_TrayName { get; set; }
        public string Tray_TrayDescription { get; set; }
        public string Tray_TrayStatus { get; set; }
        public string Tray_Note { get; set; }
        public string Tray_TrayLine { get; set; }
        public string Tray_TrayStation { get; set; }
        public int? Tray_UsedTimes { get; set; }
        public int? Tray_PlannedTimes { get; set; }

    }

}